package org.theSeed.fileContract.pojo.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import lombok.Getter;
import lombok.Setter;
import org.theSeed.base.exp.ServiceExp;
import org.theSeed.base.pojo.constant.SysConstant;
import org.theSeed.fileContract.exp.FileUploadExp;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class SeedUploadChipFileExtDto {
    /**
     * 合约实例名称
     */
    private String contractTypeInstance;

    /**
     * 单片最大大小
     */
    private Long chipFileSize;

    /**
     * 片数量
     * 上传需要从o开始计数
     */
    private Long chipSize;

    /**
     * 合并标识
     */
    private Boolean canMergeFlag = false;


    /**
     * 添加扩展信息
     */
    private Map<String, Object> addExtInfo;

    /**
     * 创建标准化分片入参
     * @param chipData
     * @return
     */
    public static SeedUploadChipFileExtDto createSeedUploadChipFileExtDto(Map<String, Object> chipData){
        try{
            String jsonStr = JSONUtil.toJsonStr(chipData);
            Map<String, Object> addExtInfo = JSONUtil.toBean(jsonStr, HashMap.class);
            addExtInfo.remove("contractTypeInstance");
            addExtInfo.remove("chipFileSize");
            addExtInfo.remove("canMergeFlag");
            addExtInfo.remove("canMergeFlag");
            SeedUploadChipFileExtDto seedUploadChipFileExtDto = BeanUtil.mapToBean(chipData, SeedUploadChipFileExtDto.class, true, SysConstant.copyOptions);
            seedUploadChipFileExtDto.setAddExtInfo(addExtInfo);
            return seedUploadChipFileExtDto;
        }catch (Exception exp){
            throw new FileUploadExp("文件参数异常:类型转换异常");
        }
    }
}